/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lolbuilder.calculation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import lolbuilder.Items.Interf.ItemsSuper;
import lolbuilder.build.Build;

/**
 *
 * @author chocoboSan
 */
public class ItemBuildPusherThread extends Thread{
    public ItemBuildPusherThread left=null;
    public Stack<Build> workingDatas=new Stack<Build>();
    public Stack<Build> outputDatas=new Stack<Build>();
    HashMap<String,Integer> buildsFound=new HashMap<String, Integer>();
    public boolean noStopMe=true;
    
    public void run() {
        while (noStopMe || left.outputDatas.size()>0) {
            Build toworkOn=null;
            synchronized(left.outputDatas) {
                if (left.outputDatas.size()==0) {
                    try {
                        left.outputDatas.wait();
                    } catch (InterruptedException ex) {
                        Logger.getLogger(ItemBuildPusherThread.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    continue;
                }
                toworkOn=left.outputDatas.pop();
                left.outputDatas.notify();
            }
            ArrayList<String> ss= new ArrayList<String>();
            for (ItemsSuper i : toworkOn.items) {                    
                ss.add(i.name);
            }
            Collections.sort(ss);
            String s="";
            for (String s2 : ss) s+=s2;
            if (buildsFound.get(s)==null) {
                buildsFound.put(s, 1);
                synchronized(outputDatas) {
                    outputDatas.push(toworkOn);
                }
            }
        }
    }
}
